#ifndef LONGKEY_SETUP_SETUP_FILES_H_
#define LONGKEY_SETUP_SETUP_FILES_H_

#include <Windows.h>
#include <atlstr.h>
#include <vector>
#include "../base/basictypes.h"

class SetupFiles
{
public:
	explicit SetupFiles(bool is_machine);
	~SetupFiles();

	HRESULT Init();

	// Returns whether the same version of PC Agent should be over-installed.
	bool ShouldOverinstallSameVersion();

	// Installs PC Agent files but does not register or install any other
	// applications. Returns where PC Agent was installed.
	HRESULT Install();

	// Roll back the changes made during Install(). Call when Setup fails.
	// Returns S_OK if there is nothing to do.
	HRESULT RollBack();

	// Uninstalls PC Agent files installed by Install().
	void Uninstall();

	int extra_code1() const { return extra_code1_; }

private:
	// Copies the shell to the verion-independent location if needed.
	HRESULT CopyShell();

	// Determines whether to copy the shell to the version-independent location.
	HRESULT ShouldCopyShell(const CString& shell_dir, 
		bool* should_copy, bool* already_exists) const;

	// Saves the previous version of the shell in case we need to roll it back.
	HRESULT SaveShellForRollback(const CString& shell_install_path);

	// Creates the lists of files that belong to PC Agent.
	HRESULT BuildFileLists();

	// Copies file_names from the current directory to the destination directory.
	HRESULT CopyInstallFiles(const std::vector<CString>& file_names,
		const CString& destination_dir,
		bool overwrite);

	// Copies each file from the source path to its corresponding destination
	// path. 
	HRESULT CopyAndValidateFiles(
		const std::vector<CString>& source_file_paths,
		const std::vector<CString>& destination_file_paths,
		bool overwite);

	// Returns whether an older shell version is compatible.
	static bool IsOlderShellVersionCompatible(ULONGLONG version);

	const bool is_machine_;
	CString saved_shell_path_;
	std::vector<CString> core_program_files_;
	std::vector<CString> optional_files_;

	int extra_code1_;

	DISALLOW_EVIL_CONSTRUCTORS(SetupFiles);
};

#endif	// LONGKEY_SETUP_SETUP_FILES_H_